Page({
    data: {
         menuList:[{
          name:'全部',
          id:0
         },{
          name:'待付款',
          id:1
         },{
          name:'待收货',
          id:3
         },{
          name:'已完成',
          id:4
         },{
          name:'已取消',
          id:5
         }],
         goodsList:[],
         selectId:0,
         num:0,
         current:1,
         pagesize:10
    },
    onLoad:function(opt){
       var userInfo= wx.getStorageSync('userInfo');
        this.setData({
            userInfo:userInfo
        })
       this.getGoods()

    },
    onShow:function(){
       
    },
  //上拉加载更多
    onReachBottom:function(){
       console.log('加载更多')
        this.setData({
          current:this.data.current+1
        })
        if (this.data.current<=this.data.totalPage) {
          this.getGoods();
        }else{
          this.setData({
            moreText:'没有更多了'
          })
        }
        
    },
    chooseType:function(e){
      console.log(e.currentTarget.dataset.id)
      this.setData({
        selectId:e.currentTarget.dataset.id,
        current:1,
        goodsList:[]
      })
      this.getGoods()
    },
    getGoods:function(){
      var url;
      if (this.data.selectId==0) {
        url=getApp().globalData.baseUrl+'/pj/order/getList?pagesize='+this.data.pagesize+'&current='+this.data.current+'&openid='+this.data.userInfo.openid
      }else{
        url=getApp().globalData.baseUrl+'/pj/order/getList?pagesize='+this.data.pagesize+'&current='+this.data.current+'&status='+this.data.selectId+"&openid="+this.data.userInfo.openid
      }
       var _self=this;
        wx.request({
            url:url,
            method:"get",
            header:{
               'openid':this.data.userInfo.openid, //公用请求头
               'content-type': 'application/json'
            },
            success: function(res) {
              if (res.data.code==200) {
                _self.setData({
                    goodsList:_self.data.goodsList.concat(res.data.obj.list),
                    totalPage:res.data.obj.pages
                })
              }
            console.log(res)  
            
         }
       })  
    },
    turnDetail:function(e){
        console.log(e);
        wx.navigateTo({
        url: '/pages/orderDetil/orderDetil?id='+e.currentTarget.dataset.code
      })
    },
    turnPage:function(){
       wx.navigateTo({
        url: '/pages/shopMarket/shopMarket'
      })
    }

});





